App.controller("unionOrderActivityCtrl",function($scope, $rootScope, $location, $http, $compile, $stateParams, $timeout, path, publicService) {
	
	$scope.search = {};
	
	
	//表格对象
	$scope.gridOptions = {
			dataSource : {
				transport : {
					read : {
						url : path+"/server/queryplatformpromotionListByPage",
						type : 'POST',
						dataType : "json",
						contentType : "application/json"
					},
					parameterMap : function(options, operation) {
						if (operation == "read") {
							var parameter = {
								page : options.page, //当前页
								pageSize : options.pageSize,
								param:{
									/*title: $scope.search2.activity_name,	 	//活动名称
									state: $("#activity_state2").data("kendoDropDownList").value(),			//活动状态
									create_time1: $("#create_time2_1").val(),	//创建日期
									create_time2: $("#create_time2_2").val(),	//创建日期
									start_time1: $("#start_time2_1").val(),	//发布日期
									start_time2: $("#start_time2_2").val(),	//发布日期
*/								}
							};
							console.log('查询参数',parameter);
							return kendo.stringify(parameter);
						}
					},
				},
				pageSize : 10,
				serverPaging : true,
				serverSorting: true,
				schema : {
					data : function(d) {
						return d.data;
					},
					total : function(d) {
						return d.total; //总条数
					}
				},
			},
			pageable : {  //分页
				pageSizes: [10, 20, 50, 100],  //每页显示记录数
			  },  
			sortable: {   //排序
				//allowUnsort: false,  //允许无序
			    mode: "multiple"     //排序模式：single，multiple
			  },
			editable: false,  //true：单个编辑；popup：弹出新页面编辑
			dataBound: function () {   //序号
		        var rows = this.items();
		        var page = this.pager.page() - 1;
		        var pagesize = this.pager.pageSize();
		        $(rows).each(function () {
		            var index = $(this).index() + 1 + page * pagesize;
		            var rowLabel = $(this).find(".row-number");
		            $(rowLabel).html(index);
		        });
		    },
			columns : [
					{    
						title : "序号",
						field : "id", 
						width : "50px",
						template:"<input type='checkbox' class='recordClass' value='#: id #' />"+"<span class='row-number subTitle'></span>"
					},
					{
						field : "",         
						title : "封面图",     
						width : "100px"
					},
					{
						field : "",         
						title : "活动名称",     
						width : "100px"
					},
					{
						field : "",         
						title : "创建者",     
						width : "100px"
					},
					{
						field : "",         
						title : "创建日期",     
						width : "100px"
					},
					{
						field : "",         
						title : "开始日期",     
						width : "200px"
					},
					{
						field : "",         
						title : "结束日期",     
						width : "200px"
					},
					{
						field : "",         
						title : "状态",     
						width : "100px",
						values: [
						         { text: "未开始", value: 0 },
						         { text: "进行中", value: 1 },
						         { text: "已结束", value: 2 }
				        ],
					},
					{
						field : "",         
						title : "操作",     
						width : "100px",
						template: function(e){
					    	var html = '';
					    	
					    	if(userInfo.user_type==1){  //开发者
					    		
					    	}else if(userInfo.user_type==2){  //企业
					    		
					    	}else if(userInfo.user_type==3){  //合伙人
					    		
					    	}else if(userInfo.user_type==4){  //品牌
					    		
					    	}else if(userInfo.user_type==5){  //专卖店
					    		
					    	}

					    	return html;
					    },
					}
			]
	};
	
	//查询
	$scope.search = function(){
		$scope.grid.dataSource.page(1);
	}
	
	//全选，取消
	$scope.chooseAll = function(className,flag){
		publicService.chooseAllByClassName(className,flag);
	}
	
	//发布活动
	$scope.addActivity = function(){
		var params = {method:"add"};
		$location.path("/addUnionOrderActivity/"+angular.toJson(params));
	}
	
	//活动审核
	$scope.activityCheck = function(){
		$location.path("/activityCheck");
	}
	
	publicService.initActivityState("activityState");				//初始化【活动状态】
	publicService.initDateTime("startTime");	//开始时间
	publicService.initDateTime("endTime");		//结束时间
	publicService.initActivityShowHidden("activityShowHidden");		//初始化【活动显示隐藏】
	
	
	
});